<template>
    <div class="box">
        <header>
            <van-nav-bar title="添加新地址" left-text="返回" left-arrow @click-left="$router.back()" />
        </header>
        <div class="content">
            <van-address-edit :area-list="areaList" show-postal show-delete show-set-default show-search-result
                :search-result="searchResult" :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave"
                @delete="onDelete" @change-detail="onChangeDetail">
            </van-address-edit>
        </div>
    </div>
</template>
<script>
import Vue from "vue";
import { NavBar, AddressEdit, Toast } from "vant";
import { areaList } from '@vant/area-data';

import { Address, UpOrderAddress } from '@/api/order'

Vue.use(NavBar);
Vue.use(AddressEdit);

export default {
    data() {
        return {
            areaList: areaList,
            searchResult: [],
        };
    },
    methods: {
        onSave(content) {
            console.log(content);
            Toast('添加成功');
            content.userid = localStorage.getItem('userid')
            Address(content).then(res => {
                content.time = this.$route.params.time
                console.log(res);
                UpOrderAddress(content).then(res1 => {
                    console.log(res1);
                    this.searchResult = res1.data
                    this.$router.back()
                })
            })
        },
        onDelete() {
            Toast('删除成功');
        },
        onChangeDetail(val) {
            // if (val) {
            //     this.searchResult = [
            //         {
            //             name: '',
            //             address: '',
            //         },
            //     ];
            // } else {
            //     this.searchResult = [];
            // }
        },
    },
};
</script>
